package com.modulethree.homework2;

/*
(1)定义一个Worker类型(属性私有、空参有参构造、set、get方法、toString方法、equals方法、hashCode方法)，包含三个属性：姓名(String name)、年龄(int age)、工资(double salary),在Worker类中定义work方法打印一句话，如："凤姐 正在工作"，其中"凤姐"代表当前对象的姓名

 (2)定义List集合，在List集合中增加三个员工，基本信息如下：

 "凤姐" 18 20000

 "欧阳峰" 60 8000

 "刘德华" 40 30000

 (4)在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300

 (5)删除"刘德华"的信息

 (6)利用for 循环遍历，打印List 中所有员工的信息

 (7)利用迭代遍历，对List 中所有的员工调用work 方法

 (8)为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true

作者：翁海龙
 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public class Worker {

    private  String name;
    private  int age;
    private double salary;

    public Worker() {
    }

    public Worker(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Worker worker = (Worker) o;
        return age == worker.age && Double.compare(worker.salary, salary) == 0 && Objects.equals(name, worker.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, salary);
    }
    public void work(){
        System.out.println(name+"正在工作");
    }

    public static void main(String[] args) {

        List list1=new ArrayList();
        list1.add(new Worker("凤姐" ,18, 20000));
        list1.add(new Worker("欧阳峰", 60 ,8000));
        list1.add(new Worker("刘德华", 40, 30000));
        list1.add(1,new Worker( "张柏芝" ,35 ,3300));
        System.out.println("list="+list1);
        list1.remove(3);
        for (int i=0;i< list1.size();i++){
            System.out.println("List 中第"+(i+1)+"位员工的信息="+list1.get(i));
        }
        Iterator it =list1.iterator();
        while(it.hasNext()){
            ((Worker)(it.next())).work();

        }
    }
}
